﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using UCLibrary.UC;
using System.Data.SQLite;

namespace 项目框架
{
    public partial class Form1 : Form
    {
        public static Data data = new Data();
        public Form1()
        {
            InitializeComponent();
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.StartPosition = FormStartPosition.CenterScreen;
            label1.DataBindings.Add("Text",data,"Text");

        }
        public static void UpdataStatus(bool b)
        {
            data.Status = b;
        }
        FrmPlc frmPlc = new FrmPlc();
        FrmAlarm frmAlarm = new FrmAlarm();
        private void selectBtn(object sender, EventArgs e)
        {
            UCBtn btn = sender as UCBtn;
            Form frm = null;
            //遍历后改变按钮颜色
            foreach(UCBtn bt in panel1.Controls)
            {
                bt.backgroundColor = Color.DimGray;
            }
            btn.backgroundColor = this.panel1.BackColor;
            switch (btn.TabIndex)
            {
                case 0:
                    frm = new FrmMain();
                    break;
                case 1:
                    frm = frmPlc;
                    break;
                case 2:
                    frm = frmAlarm;
                    break;
                case 3:
                    frm = new FrmSignal();
                    break;
            }
            //遍历窗体控件后关闭窗体
            foreach (Form fr in this.panel2.Controls)
            {
                if (fr.Text != "FrmPlc" && fr.Text != "FrmAlarm")
                    fr.Close();
            }
            this.panel2.Controls.Clear();
            if (frm != null)
            {
                //当前的窗体设定为父
                this.IsMdiContainer = true;
                frm.MdiParent = this;
                frm.Parent = panel2;
                frm.Dock = DockStyle.Fill;
                frm.Show();
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            selectBtn(ucBtn1,e);
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Environment.Exit(0);
        }

        private void ucBtn5_Click(object sender, EventArgs e)
        {
        }

        private void ucBtn5_Click_1(object sender, EventArgs e)
        {
        }
    }
}
